#ifndef MEMORY_H
#define MEMORY_H

#include "ipc/mutex.h"
#include "tools/bitmap.h"
#include "comm/types.h"
#include "comm/boot_info.h"
#include "cpu/mmu.h"

#define MEM_EXT_START 0x100000
#define MEM_PAGE_SIZE 0x1000
#define MEM_EBDA_START  0x00080000
#define MEM_EXT_END  (128*1024*1024 - 1)
#define MEMORY_TASK_BASE 0x80000000        // 进程起始地址空间

typedef struct _addr_alloc_t {
    mutex_t mutex;
    bitmap_t bitmap;
    uint32_t start;
    uint32_t size;
    uint32_t page_size;
} addr_alloc_t;

typedef struct _memory_map_t {
    void *vstart;
    void *vend;
    void *pstart;
    uint32_t perm;
} memory_map_t;

void memory_init(boot_info_t *boot_info);
uint32_t memory_create_uvm();
int memory_alloc_page_for(uint32_t addr, uint32_t size, int perm);

#endif